package com.atguigu.springcloud.alibaba.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author xiaolong
 * @version 1.0
 * @description: TODO
 * @date 2021/9/24 11:21
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Long, Payment> hashMap = new HashMap<Long, Payment>();


    static {
        hashMap.put(1L, new Payment(1L, "sad54f65a154d6s4da5sd1"));
        hashMap.put(2L, new Payment(2L, "sad54f65a154d6s4da5sd1"));
        hashMap.put(3L, new Payment(3L, "sad54f65a154d6s4da5sd1"));
    }


    @GetMapping(value = "/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id) {
        return "nacos registry serverport:" + serverPort + "\t id" + id;
    }


    @GetMapping(value = "/paymentSQL/{id}")
    public CommonResult<Payment> getPaymentSQL(@PathVariable("id") Long id) {
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result = new CommonResult(200, "from mysql,serverPort :" + serverPort, payment);
        return result;
    }


}
